package com.yc.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yc.base.BaseServiceImpl;
import com.yc.user.entity.UserRoleRelation;
import com.yc.user.mapper.UserRoleRelationMapper;
import com.yc.user.service.IUserRoleRelationService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 后台用户和角色关系表 服务实现类
 * </p>
 *
 * @author bao
 * @since 2021-12-09
 */
@Service
public class UserRoleRelationServiceImpl extends BaseServiceImpl<UserRoleRelationMapper, UserRoleRelation> implements IUserRoleRelationService {
    @Override
    public boolean create(UserRoleRelation userRoleRelation) {
        return save(userRoleRelation);
    }

    @Override
    public boolean createBatch(List<UserRoleRelation> userRoleRelationList) {
        return saveBatch(userRoleRelationList);
    }

    @Override
    public boolean delete(List<Long> ids) {
        return removeByIds(ids);
    }

    @Override
    public boolean deleteByUid(Long uid) {
        UpdateWrapper<UserRoleRelation> wrapper = new UpdateWrapper<>();
        wrapper.lambda().eq(UserRoleRelation::getUserId, uid);
        return remove(wrapper);
    }

    @Override
    public boolean deleteByUids(List<Long> ids) {
        UpdateWrapper<UserRoleRelation> wrapper = new UpdateWrapper<>();
        wrapper.lambda().in(UserRoleRelation::getUserId, ids);
        return remove(wrapper);
    }

    @Override
    public boolean update(UserRoleRelation userRoleRelation) {
        return updateById(userRoleRelation);
    }

    @Override
    public UserRoleRelation queryById(Long id) {
        return getById(id);
    }

    @Override
    public List<UserRoleRelation> selectList() {
        QueryWrapper<UserRoleRelation> wrapper = new QueryWrapper<>();
        wrapper.lambda().orderByDesc(UserRoleRelation::getId);
        return list(wrapper);
    }

    @Override
    public Page<UserRoleRelation> selectPage(Integer pageNum, Integer pageSize) {
        QueryWrapper<UserRoleRelation> wrapper = new QueryWrapper<>();
        wrapper.lambda().orderByDesc(UserRoleRelation::getId);
        Page<UserRoleRelation> page = new Page<>(pageNum, pageSize);
        return page(page, wrapper);
    }
}
